home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / GuiLib / Wimp / h / GuiBBox < prev    next >
Text File  |  2003-02-14  |  4KB  |  84 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #ifndef GuiBBox_h
  39. #define GuiBBox_h
  40.  
  41. #include "stl:bool.h"
  42.  
  43. class GuiBBox
  44. {
  45.   public:
  46.     int xmin, ymin, xmax, ymax;
  47.  
  48.     void set(int x_min,int y_min,int x_max,int y_max)        { 
  49.                                                                xmin = x_min;  xmax = x_max;
  50.                                                                ymin = y_min;  ymax = y_max;
  51.                                                              }
  52.     void operator()(int x_min,int y_min,int x_max,int y_max) { 
  53.                                                                xmin = x_min;  xmax = x_max;
  54.                                                                ymin = y_min;  ymax = y_max;
  55.                                                              }
  56.  
  57.     
  58.     int  getWidth() const             {return xmax-xmin;}
  59.     void setWidth(int width)          {xmax=xmin+width;}
  60.  
  61.     int  getHeight() const            {return ymax-ymin;}
  62.     void setHeight(int height)        {ymax=ymin+height;}
  63.  
  64.     int  getDepth() const             {return ymax-ymin;}
  65.     bool overlap(const GuiBBox& b) const
  66.                      {return !(xmin>=b.xmax || xmax<=b.xmin || ymax<=b.ymin || ymin>=b.ymax);}
  67.     void moveBy(int x,int y)               {xmin+=x;xmax+=x;ymin+=y;ymax+=y;}
  68.     void moveTo(int left_x,int top_y)      {
  69.                                              xmax=left_x+getWidth();xmin=left_x;
  70.                                              ymin=top_y-getDepth();ymax=top_y;
  71.                                            }
  72.     void centreInBox(const GuiBBox& b)    {
  73.                                              int size=getWidth();
  74.                                              xmin=(b.xmin+b.xmax-size)/2;
  75.                                              xmax=xmin+size;
  76.                                              size=getHeight();
  77.                                              ymin=(b.ymin+b.ymax-size)/2;
  78.                                              ymax=ymin+size;
  79.                                            }
  80. };
  81.  
  82.  
  83. #endif
  84.